package com.hyts.standard.webflux.web.rest;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Splitter;
import com.hyts.standard.webflux.client.HttpRequestClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

import javax.annotation.PostConstruct;
import java.time.Duration;

/**
 * project-name:standard-webflux
 * package-name:com.hyts.standard.webflux.controller
 * author:Libo/Alex
 * create-date:2019-06-19 10:40
 * email:liboware@gmail.com
 * description:此类主要用于:
 */
@RestController
public class BaseController {

    static final Splitter splitter = Splitter.on(",").trimResults();

    @Autowired
    HttpRequestClient httpRequestClient;

    @Autowired
    RestTemplate restTemplate;


    @GetMapping("/baidu")
    public Mono<String> baidu() {
        return httpRequestClient.get("http://www.baidu.com/");
    }


    @GetMapping("/hello")
    public Mono<String> hello() {
        return Mono.just("Welcome to reactive world ~").delayElement(Duration.ofMillis(1000));
    }


    @GetMapping("/hello2")
    public Mono<String> hello2() {
        String htmlContent = restTemplate.getForObject("http://www.baidu.com", String.class);
        return Mono.fromCallable(() -> htmlContent).subscribeOn(Schedulers.elastic());
    }

    //
//    public static void main(String[] args) {
//        new UserPO().notifyMessage();
//    }

    public static void main(String[] args) {
        String srtr = "https://open.larksuite.com/open-apis/bot/v2/hook/fbd36f4c-c8d4-49ee-9715-c87b087e85eb,https://open.larksuite.com/open-apis/bot/v2/hook/ea9b840d-3657-44e5-8bf7-d990b9b0c402";
        System.out.println(splitter.splitToList(srtr));
    }

}
